package com.doge.calcalbum.business.entry

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.doge.calcalbum.db.model.Album
import com.doge.calcalbum.db.model.Entry
import java.io.File

class EntryViewModel constructor(
    private val repository: EntryRepository
) : ViewModel() {
    val album: LiveData<Album?> = repository.album
    val entryList: LiveData<List<Entry>> = repository.entryList

    fun markDeleted(data: List<Entry>) {
        repository.markDeleted(data)
    }

    fun moveToAlbum(data: List<Entry>, albumId: Int) {
        if (repository.albumId == albumId) return
        if (data.isEmpty()) return
        repository.moveToAlbum(data, albumId)
    }
}

class EntryViewModelFactory(private val requestId: Int) : ViewModelProvider.Factory {
    override fun <T : ViewModel?> create(modelClass: Class<T>): T {
        val repository = EntryRepository(requestId)
        if (modelClass.isAssignableFrom(EntryViewModel::class.java)) {
            return EntryViewModel(repository) as T
        }
        //noinspection unchecked
        throw IllegalArgumentException("Unknown ViewModel class")
    }
}


